package com.kiln.juxingqs.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import client.global.commlib.network.data.Ret
import com.kiln.juxingqs.api.bean.RechargeOrders2
import com.kiln.juxingqs.ui.viewmodel.MiddleVm
import kotlinx.coroutines.flow.*

class CreateRechargeViewModel(app: Application) : MiddleVm(app) {

    val isShowing = MutableLiveData<Boolean>(false)
    val num = MutableLiveData<String>()
    val okCall = MutableLiveData<JsonResult<RechargeOrders2>>()
    val txType = MutableLiveData<Int>(-1)

    /**
     * 三方支付
     */
    fun checkPay3() {
        txType.value = 2
    }

    /**
     * 银行卡
     */
    fun checkBank() {
        txType.value = 3
    }

    fun checkBank2() {
        txType.value = 4
    }

    fun checkBankDe() {
        txType.value = 5
    }

    fun checkKuaijie() {
        txType.value = 6
    }

    /**
     * 翼支付方式充值
     */
    fun checkBestPaye() {
        txType.value = 2
    }

    /**
     * 充值 / 一键充值？
     */
    fun checkYj() {
        txType.value = 2
    }

    /**
     * 手动充值
     */
    fun checkIncome() {
        txType.value = 1
    }


    fun ok() {
        this@CreateRechargeViewModel.isShowing.value = true
        hold({
            server.recharge_orders2(num.value!!, "${txType.value}")
        }, {
            isShowing.value = true
        }, success = {
            okCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }

    fun ok3(tokenNo: String) {
        this@CreateRechargeViewModel.isShowing.value = true
        hold({
            server.recharge_orders3(num.value!!, "${txType.value}", tokenNo)
        }, {
            isShowing.value = true
        }, success = {
            okCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }


}